package DIYException;

import java.util.Scanner;

public class Login {
    private String name;
    private String password;

    public Login(String name, String password) {
        this.name = name;
        this.password = password;
    }

    private void loginInto(String name, String password) throws UserNameException,UserPasswordException{
        if (!this.name.equals(name)){
            throw new UserNameException("用户名异常...");
        }
        if (!this.password.equals(password)){
            throw new UserPasswordException("密码异常...");
        }
    }

    public void loging(){
        Scanner inPut = new Scanner(System.in);
        try {
            System.out.println("请输入用户名:");
            String name = inPut.nextLine();
            System.out.println("请输入密码:");
            String password = inPut.nextLine();
            this.loginInto(name,password);
        }catch (UserNameException e){
            e.printStackTrace();
            return;
        }catch (UserPasswordException e){
            e.printStackTrace();
            return;
        }finally {
            inPut.close();
        }
        System.out.println("登陆成功...");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static void main(String[] args) {
        Login user = new Login("t","1230");
        user.loging();
    }
}
